// 扩展原生对象方法
const formatType = {
    1: 'yyyy-MM-dd',
    2: 'yyyy/MM/dd',
    3: 'HH:mm:ss',
    4: 'HH:mm',
    5: 'yyyy.MM.dd',
    6: 'yyyy年MM月dd日',
    7: 'yyyy/MM/dd HH:mm'
}
Date.prototype.format = function (type) {
    console.log('扩展原生对象方法', formatType[type], this)
    if (this) {
        let year = this.getFullYear(),
            month = this.getMonth() + 1,
            date = this.getDate(),
            hour = this.getHours(),
            minutes = this.getMinutes(),
            seconds = this.getSeconds(),
            str = '';
        switch (type) {
            case 1:
                str = `${year}-${month}-${date}`;
                break;
            case 2:
                str = `${year}/${month}/${date}`;
                break;
            case 3:
                str = `${hour}:${minutes}:${seconds}`;
                break;
            case 4:
                str = `${hour}:${minutes}`;
                break;
            case 5:
                str = `${year}.${month}.${date}`;
                break;
            case 6:
                str = `${year}年${month}月${date}日`;
                break;
            case 7:
                str = `${year}/${month}/${date} ${hour}:${minutes}`;
                break;
            default:
                str = '(获取日期时间失败！)';
                break;
        }
        return str;
    }
    return false;
}